﻿@using BootstrapBlazor.Components
@using TrackSystem.Entities.Dtos.Var
@using TrackSystem.Entities.Extensions


<p>@(Reg.Description ??= "无描述")</p>
<p>分类: @_AttrDesc </p>

<Divider class="mt-3 mb-3" />

@{
    var pos = Reg.Name.IndexOf('_');
    var desc1 = "";
    var desc2 = "";
    if (pos > 0)
    {
        desc1 = Reg.Name[..pos];
        desc2 = Reg.Name[(pos + 1)..];
    }

    @switch (Reg.Serial)
    {
        case VarSerialEnum.Sensor:
        case VarSerialEnum.Attr_Sensor:
            <p>传感器名称: @desc1 (@Reg.snrloopId) </p>
            <p>寄存器名称: @desc2 (@Reg.snrloopIndex)</p>
            break;
        case VarSerialEnum.Attr_Channel:
            <p>通道名称: @desc1 (@Reg.snrloopId)</p>
            <p>通道属性: @desc2 (@Reg.snrloopIndex)</p>
            break;
        case VarSerialEnum.Attr_Logic:
            <p>逻辑名称: @desc1 (@Reg.snrloopId)</p>
            <p>逻辑属性: @desc2 (@Reg.snrloopIndex)</p>
            break;
        case VarSerialEnum.Attr_Slave:
            <p>从站名称: @desc1 (@Reg.snrloopId)</p>
            <p>从站属性: @desc2 (@Reg.snrloopIndex)</p>
            break;
        case VarSerialEnum.Loop:
            <p>回路名称: @desc1 (@Reg.snrloopId)</p>
            <p>回路属性: @desc2 (@Reg.snrloopIndex)</p>
            break;
        case VarSerialEnum.Attr_Record:
            <p>记录名称: @desc1 (@Reg.snrloopId)</p>
            <p>记录属性: @desc2 (@Reg.snrloopIndex)</p>
            break;        case VarSerialEnum.UserDefine:
        default:
            <p></p>
            <p></p>
            break;
    }
}

<div class="row">
    <div class="col-6"> <Switch IsDisabled="true" Value="@Reg.ReadOnly" OnColor="Color.Success" OnText="只读" OffText="读写"></Switch></div>
    <div class="col-6"> @Reg.DataType.ToString()</div>
</div>

<div class="row">
    <div class="col-6">
        <Switch IsDisabled="true" Value="@Reg.IsRecord" OnColor="Color.Success" OnText="记录" OffInnerText="否" OnInnerText="是"></Switch>
    </div>
    <div class="col-6"> @Reg.RecordCycle ms</div>
</div>

<div class="row">
    <div class="col-6">报警方式</div>
    @{
        var alm = "不报警";
        switch (Reg.AlarmSetting)
        {
            case AlarmTypeEnum.High: alm = "高报警";   break;
            case AlarmTypeEnum.Low: alm = "低报警";    break;
            case AlarmTypeEnum.HighLow: alm = "高低报警"; break;
            default: alm = "不报警"; break;
        }
        <div class="col-6">@alm</div>
    }
</div>

<div class="row">
    <div class="col-6">报警范围</div>
    <div class="col-6">@Reg.LowAlarmSet - @Reg.HighAlarmSet</div>
</div>



@code{
    [Parameter]
    public required VarDto Reg { get; set; }

    private string _AttrDesc { get; set; } = "";

    protected override void OnInitialized()
    {
        base.OnInitialized();
        switch (Reg.Serial)
        {
            case VarSerialEnum.Sensor:      _AttrDesc = "传感器寄存器"; break;
            case VarSerialEnum.Attr_Sensor: _AttrDesc = "传感器属性";  break;
            case VarSerialEnum.Attr_Channel:_AttrDesc = "端口属性";    break;
            case VarSerialEnum.Attr_Logic:  _AttrDesc = "逻辑属性";    break;
            case VarSerialEnum.Attr_Slave:  _AttrDesc = "从站属性";    break;
            case VarSerialEnum.Loop:        _AttrDesc = "回路属性";    break;
            case VarSerialEnum.Attr_Record: _AttrDesc = "记录属性";    break;
            case VarSerialEnum.UserDefine:  _AttrDesc = "自定义";     break;
        }
    }

}
